package com.lfd.rocketmq.listener;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * @项目名： spring-emq
 * @包名： com.lfd.rocketmq.listener
 * @文件名: ObjListMsgListener
 * @创建者: liufudong@szyh-smart.com
 * @创建时间: 2024/10/1 20:38
 * @描述：
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = "powernode-list",
        consumerGroup = "powernode-list",   messageModel = MessageModel.CLUSTERING)
public class ObjListMsgListener implements RocketMQListener<Object> {
    private BigDecimal bigDecimal;
    @Autowired
    private ObjectMapper objectMapper;
    @Override
    public void onMessage(Object o) {
        if (o instanceof List) {
            List<Object> list = (List<Object>) o;
            list.forEach(obj -> {
                try {
                    log.info("ObjListMsgListener onMessage obj:{}",
                            objectMapper.writeValueAsString(obj));
                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }
            });
        }

    }
}
